package com.powernode.config;

import com.powernode.interceptors.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration//表名是一个配置类
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    LoginInterceptor loginInterceptor;

    //给自定拦截器赋值
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                //第一个拦截所有
                .addPathPatterns("/**")
                //放行的资源  这里的helo为controller方法的虚拟路径
                //不纠结了加了/hello或hello打印效果不一样
                .excludePathPatterns("/page/toLogin.do")
                .excludePathPatterns("/index.html")
                .excludePathPatterns("/login/doLogin.do")
                .excludePathPatterns("/captcha.do")
                .excludePathPatterns("/file/download.do")
//               这个resource为static下的resource
                .excludePathPatterns("/resources/**")
//               放行swagger-ui
                .excludePathPatterns("/swagger-ui/**");

//       <mvc:mapping path="/**"/>  之前springmvc中配置，现在springboot中没有了xml
//            <!--            下面这个是不拦截哪一个controller方法-->
//<!--            转发登录界面放行-->
//            <mvc:exclude-mapping path="/page/toLogin.do"/>
//<!--            验证验证码放行-->
//            <mvc:exclude-mapping path="/login/doLogin.do"/>
//<!--            以流的形式写验证码放行-->
//            <mvc:exclude-mapping path="/captcha.do"/>
//<!--            放行静态文件-->
//            <mvc:exclude-mapping path="/resources/**"/>
//            <!--            配饰自定义拦截器-->
//            <bean id="myInteceptor" class="com.powernode.interceptors.LoginInterceptor"></bean>

    }
}
